package com.aj.activity;

import com.aj.activity.dialog.ProgressDialog;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TitleBarBaseActivity extends FragmentActivity {

    private TextView mPageBackButton;
    private TextView mTitleTextView;
    private TextView mPageRightButton;
    private TextView mPageRightButtonOne;
    private LinearLayout mContentLayout;

    protected ProgressDialog progressDialog;

    protected void showProgressDialog(String text) {
        if (progressDialog == null) {
            progressDialog = new ProgressDialog(this);
        }
        progressDialog.show();
        progressDialog.setContentText(text);
    }

    protected void dimissProgressDialog() {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
            progressDialog = null;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.titlebar_layout);
        initTitleBar();
    }

    private void initTitleBar() {
        mPageBackButton = (TextView) findViewById(R.id.pageBackButton);
        mTitleTextView = (TextView) findViewById(R.id.pageCenterTitle);
        mPageRightButton = (TextView) findViewById(R.id.pageRightButton);
        mPageRightButtonOne = (TextView) findViewById(R.id.pageRightButtonOne);
        mContentLayout = (LinearLayout) findViewById(R.id.pageContent);
    }

    public void setTitle(int resId) {
        mTitleTextView.setText(getResources().getString(resId));
    }

    public void setTitle(CharSequence title) {
        mTitleTextView.setText(title);
    }

    public void setTitleTextColor(int color) {
        mTitleTextView.setTextColor(color);
    }

    public void setTitleTextSise(float size) {
        mTitleTextView.setTextSize(size);
    }

    protected TextView getTitleLeftButton() {
        mPageBackButton.setVisibility(View.VISIBLE);
        return mPageBackButton;
    }

    protected TextView getTitleRightButton() {
        mPageRightButton.setVisibility(View.VISIBLE);
        return mPageRightButton;
    }

    protected TextView getTitleRightButtonOne() {
        mPageRightButtonOne.setVisibility(View.VISIBLE);
        return mPageRightButtonOne;
    }

    @SuppressWarnings("deprecation")
    public void setContentView(View view) {
        mContentLayout.removeAllViews();
        if (view != null) {
            mContentLayout.addView(view, LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
        }
    }

    @SuppressWarnings("deprecation")
    public void setContentView(int layoutResID) {
        mContentLayout.removeAllViews();
        View view = getLayoutInflater().inflate(layoutResID, mContentLayout, false);
        if (view != null) {
            mContentLayout.addView(view, LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
        }
    }

}
